package main

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/micro-plat/hydra"
	"github.com/micro-plat/hydra/components"
	"github.com/micro-plat/hydra/conf/app"
	"github.com/micro-plat/hydra/conf/server/api"
	"github.com/micro-plat/hydra/conf/server/auth"
	"github.com/micro-plat/hydra/conf/server/auth/jwt"
	"github.com/micro-plat/hydra/conf/server/header"
	"github.com/micro-plat/hydra/conf/server/nfs"
	"github.com/micro-plat/hydra/conf/server/static"
	"github.com/micro-plat/hydra/hydra/servers/http"
)

// init 检查应用程序配置文件，并根据配置初始化服务
func init() {
	//启动时参数配置检查
	App.OnStarting(func(conf app.IAPPConf) error {
		//检查DB
		if _, err := components.Def.DB().GetDB(); err != nil {
			return err
		}
		return nil
	}, http.Web)

	exp := auth.GetExcludes()
	exp = append(exp, "/**")

	hydra.Conf.Web("8080", api.WithTimeout(300, 300)).
		Static(static.WithAssetsPath("./upload"),
			static.WithAutoRewrite(),
			static.WithUnrewrite("/**/*.md", "/**/*.jpg")).
		Header(header.WithCrossDomain()).
		NFS("./upload", nfs.WithDomain("/"), nfs.WithUpload("/file/upload"), nfs.WithRename()).
		Jwt(jwt.WithMode("HS512"),
			jwt.WithSecret("bf8f3171946d8d5a13cca23aa6080c8e"),
			jwt.WithExpireAt(36000),
			jwt.WithHeader(),
			jwt.WithExcludes(exp...))

}
